package oocl.ita.eordering.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

import oocl.ita.eordering.po.Merchant;
import oocl.ita.eordering.util.BaseUtil;

@Aspect
@Component
public class SecAspect {
	private final String registPc = "execution(* oocl.ita.eordering.service.ClientService.clientRegist(..))";
	private final String loginPc = "execution(* oocl.ita.eordering.service.ClientService.clientLogin(..))";

	@Around(registPc)
	public Object registMdProcess(ProceedingJoinPoint jp) {
		Object o = null;
		Merchant stu = (Merchant) jp.getArgs()[0];
		stu.setmPassword(BaseUtil.JohnMd(stu.getmPassword(), "md5"));
		try {
			System.out.println("regist ---md5");
			o = jp.proceed();
		} catch (Throwable e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return o;
	}

	@Around(loginPc)
	public Object loginMdProcess(ProceedingJoinPoint jp) {
		Object o = null;
		String psd = (String) jp.getArgs()[1];
		try {
			System.out.println("login ---md5");
			o = jp.proceed(new Object[] { jp.getArgs()[0], BaseUtil.JohnMd(psd, "md5") });
		} catch (Throwable e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return o;
	}
}
